<!DOCTYPE html>
<html>
<!--[if IE 8]> <html lang="en" class="ie8 no-js"> <![endif]-->
<!--[if IE 9]> <html lang="en" class="ie9 no-js"> <![endif]-->
<!--[if !IE]><!-->
<!--<![endif]-->
<!-- BEGIN HEAD -->
<!-- BEGIN BODY -->
<style type="text/css">
span {
	padding-left: 15px;
}
</style>
<body class="page-header-fixed">
	<!-- BEGIN PAGE CONTENT-->
	<div class="site_content">
		<div class="realtime_content content_box no_table_filter">
			<div>
				<form class="instruct_box" id="form_id" method="post">
					<hr />
					<div>
						<div class="form-group form1 row">
							<div class="col-sm-6">
								<label class="col-sm-4">设备地址</label>
								<div class="col-sm-8">
									<input type="text" class="form-control" id="chargerId"
										name="chargerId" placeholder="请输入16位设备地址">
								</div>
								<span id="chargerInner"></span>
							</div>
							<div class="col-sm-6">
								<label class="col-sm-4">用户卡号</label>
								<div class="col-sm-8">
									<input type="text" class="form-control" id="userCard"
										name="userCard" placeholder="请输入20位用户卡号">
								</div>
								<span id="userInner"></span>
							</div>
						</div>
						<div class="form-group form1 row">
							<div class="col-sm-6">
								<label class="col-sm-4">端口号</label>
								<div class="col-sm-8">
									<input type="text" class="form-control" id="portNo"
										name="portNo" placeholder="请输入1位端口号">
								</div>
								<span id="portInner"></span>
							</div>
							<div class="col-sm-6">
								<label class="col-sm-4">控制类型</label>
								<div class="col-sm-8">
									<select id="controlType" name="controlType"
										class="form-control">
										<option name="04" value="04">自动充满为止</option>
										<option name="01" value="01">电量控制充电</option>
										<option name="02" value="02">时间控制充电</option>
										<option name="03" value="03">金额控制充电</option>
										
									</select>
								</div>
							</div>
						</div>
						<div class="form-group form1 row">
							<div class="col-sm-6">
								<label class="col-sm-4">开启限制数据</label>
								<div class="col-sm-8">
									<input type="text" class="form-control"
										id="openRestrictedData" name="openRestrictedData" placeholder="开启限制数据,只能保留两位小数">
								</div>
							</div>

						</div>

					</div>
					<div class="modal-footer t_c" style="text-align: right">
						<button style="margin-bottom: 0" type="reset"
							class="btn btn-warning" data-dismiss="modal">
							<i class="fa fa-refresh"></i> 重置
						</button>

						<button type="button" class="btn btn-primary">
							<i class="fa fa-check-circle-o"></i> 开启
						</button>
					</div>
				</form>
			</div>
		</div>
	</div>
	<!-- END PAGE CONTENT-->
	<script type="text/javascript">
		var charger = $('#chargerId');
		var user = $('#userCard');
		var port = $('#portNo');
		var set_charge = function() {

			$('#chargerId').on('blur', function() {

				if (/^\d{16}$/.test(charger.val())) {
					$('#chargerInner').html('');
					charger.isError = true;
				} else {
					$('#chargerInner').html('请输入16位设备地址').css('color', 'red');
					charger.isError = false;
				}
			});
			$('#userCard').on('blur', function() {

				if (/^\d{20}$/.test(user.val())) {
					$('#userInner').html('');
					user.isError = true;
				} else {
					$('#userInner').html('请输入20位ID').css('color', 'red');
					user.isError = false;
				}
			});
			$('#portNo').on('blur', function() {

				if (/^\d{1}$/.test(port.val())) {
					$('#portInner').html('');
					port.isError = true;
				} else {
					$('#portInner').html('请输入1位端口号').css('color', 'red');
					port.isError = false;
				}
			});
		};
		set_charge();
		$('button.btn-primary').on(
				'click',
				function() {
					if (charger.isError == true && user.isError == true
							&& port.isError == true) {
						// var charger = $('#chargerId').val();
						// var user = $('#userCard').val();
						// var port = $('#portNo').val();

						if (!!charger && !!user && !!port) {
							$.ajax({
								type : 'post',
								url : '/cms/startChargeFromOms',
								data : $('#form_id').serialize(),
								dataType : "json",
								async : false,
								success : function(data) {
									if (data.code == '200') {
										bootboxWindow.alert("指令下发成功!", null);
									} else {
										bootboxWindow.alert("指令下发失败!", null);
										$('#account').val('');
										$('#password').val('');
									}
								},
								error : function() {
									bootboxWindow.alert("连接服务器失败", null);
								}
							})

						} else {

							bootboxWindow.alert("关键字段不能为空", null);

						}
					} else {
						$('#chargerInner').html('请输入16位设备地址').css('color','red');
						$('#userInner').html('请输入20位ID').css('color', 'red');
						$('#portInner').html('请输入1位端口号').css('color', 'red');
					}

				});
	</script>
</body>
</html>

